﻿namespace Community.CsharpSqlite.Entity
{
    /*
** For each nested loop in a WHERE clause implementation, the WhereInfo
** structure contains a single instance of this structure.  This structure
** is intended to be private the the where.c module and should not be
** access or modified by other modules.
**
** The pIdxInfo field is used to help pick the best index on a
** virtual table.  The pIdxInfo pointer contains indexing
** information for the i-th table in the FROM clause before reordering.
** All the pIdxInfo pointers are freed by whereInfoFree() in where.c.
** All other information in the i-th WhereLevel object for the i-th table
** after FROM clause ordering.
*/

    public class InLoop
    {
        public int addrInTop; /* Top of the IN loop */
        public int iCur; /* The VDBE cursor used by this IN operator */
    }

    public class WhereLevel
    {
        public int addrBrk; /* Jump here to break out of the loop */
        public int addrCont; /* Jump here to continue with the next loop cycle */
        public int addrFirst; /* First instruction of interior of the loop */
        public int addrNxt; /* Jump here to start the next IN combination */
        public byte iFrom; /* Which entry in the FROM clause */
        public int iIdxCur; /* The VDBE cursor used to access pIdx */
        public int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */
        public int iTabCur; /* The VDBE cursor used to access the table */
        public byte op; /* Opcode and P5 of the opcode that ends the loop */
        public int p1, p2; /* Operands of the opcode used to ends the loop */
        public byte p5; /* Opcode and P5 of the opcode that ends the loop */


        /* The following field is really not part of the current level.  But
        ** we need a place to cache virtual table index information for each
        ** virtual table in the FROM clause and the WhereLevel structure is
        ** a convenient place since there is one WhereLevel for each FROM clause
        ** element.
        */
        public sqlite3_index_info pIdxInfo; /* Index info for n-th source table */
        public WherePlan plan; /* query plan for this element of the FROM clause */
        public _u u = new _u();

        #region Nested type: _u

        public class _u
        {
            public __in _in = new __in(); /* Used when plan.wsFlags&WHERE_IN_ABLE */

            #region Nested type: __in

            public class __in /* Information that depends on plan.wsFlags */
            {
                public InLoop[] aInLoop; /* Information about each nested IN operator */
                public int nIn; /* Number of entries in aInLoop[] */
            }

            #endregion
        }

        #endregion
    };
}